package hadoop.sort;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class SortBean implements WritableComparable<SortBean> {

    private long wordnum;

    public SortBean() {
    }



    public long getWordnum() {
        return wordnum;
    }

    public void setWordnum(long wordnum) {
        this.wordnum = wordnum;
    }

    @Override
    public String toString() {
        return "SortBean{" +
                "wordnum=" + wordnum +
                '}';
    }

    //排序方法
    @Override
    public int compareTo(SortBean o) {
        if(wordnum>o.getWordnum()){
            return -1;
        }else if(wordnum < o.getWordnum()){
            return 1;
        }else{
            return 0;
        }
    }

    //序列化
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeLong(this.wordnum);
    }

    //反序列化
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.wordnum=dataInput.readLong();
    }
}
